<?php

class Main_model extends CI_Model
{
	function __construct()
    {        
        parent::__construct();
    }
	
	public function all_patient( $last_update ) {
        $sp = "dbo.uspGetManagerEmployees @BusinessEntityID=".$last_update;
        $xResult = $this->db->query($sp);
        if ($xResult->result_array()) {
            return ($xResult->result_array());
        } else {
            return FALSE;
        }
    }
	
	public function all_doctor( $last_update ) {
        $sp = "dbo.uspGetManagerEmployees @BusinessEntityID=".$last_update;
        $xResult = $this->db->query($sp);
        if ($xResult->result_array()) {
            return ($xResult->result_array());
        } else {
            return FALSE;
        }
    }
	
	public function all_schedule( $last_update ) {
        $sp = "dbo.uspGetManagerEmployees @BusinessEntityID=".$last_update;
        $xResult = $this->db->query($sp);
        if ($xResult->result_array()) {
            return ($xResult->result_array());
        } else {
            return FALSE;
        }
    }
	
	public function all_absence( $last_update ) {
        $sp = "dbo.uspGetManagerEmployees @BusinessEntityID=".$last_update;
        $xResult = $this->db->query($sp);
        if ($xResult->result_array()) {
            return ($xResult->result_array());
        } else {
            return FALSE;
        }
    }
	
	public function all_appointment( $last_update ) {
        $sp = "dbo.uspGetManagerEmployees @BusinessEntityID=".$last_update;
        $xResult = $this->db->query($sp);
        if ($xResult->result_array()) {
            return ($xResult->result_array());
        } else {
            return FALSE;
        }
    }
	
	/*
		FUNCION : Registrar Paciente
		DETALLE : Se registra un nuevo paciente dentro de la BD SPRING
	*/
	public function register_patient($doc, $nombre, $apepat, $apemat, $sexo, $tipodoc) {

        $sp ="[dbo].[usp_Registrar_Paciente_2] 
					@numdoc = ".$doc.",
					@nombres = ".$nombre.",
					@apellidopaterno = ".$apepat.",
					@apellidomaterno = ".$apemat.",
					@sexo = ".$sexo.",
					@fechanacimiento = NULL,
					@direccion = NULL,
					@telefono_celular = NULL,
					@telefono_fijo = NULL,
					@tipodoc = ".$tipodoc.",
					@email = NULL,
					@ciudad = NULL,
					@seguro = NULL";
		
		$result = $this->db->query($sp);
		//var_dump($result->result_array());
		if ($result->result_array()) {
            return ($result->result_array());
        } else {
            return FALSE;
        }
    }
	
	/*
		FUNCION : Pre-Reservar Cita
		DETALLE : Se pre-reserva la cita de un paciente en la BD SPRING
	*/
	
    public function pre_register_app( $id_patient , $id_doctor, $id_schedule, $date, $comments) 
	{
    	$sp = "[dbo].[USP_PRE_RESERVARCITA] 
					@id_paciente = ".$id_patient.",
					@id_medico = ".$id_doctor.",
					@id_horario = ".$id_schedule.",
					@fecha_creacion = NULL,
					@comentario_situacion = NULL,
					@fechacita = NULL,
					@DuracionPromedio = NULL,
					@TipoCita = 1";
		
		$result = $this->db->query($sp);

	   if ($result->result_array()) {
            return ($result->result_array());
        } else {
            return FALSE;
        }
		
		//return "SP pre-reservar cita";
	}
	
}
?>
